<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="业务单外协项目" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doSelect(index){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr;
		if (ob_arr.length>=index){
			var obj=ob_arr[index-1];
			var thisAmount=abateMul(obj.getAttribute("i_amo"),obj.getAttribute("c_amo"));
			var sNum=getSquareNum("${priceType}",thisAmount,obj.getAttribute("i_len"),obj.getAttribute("i_wid"));
			arr=new Array(obj.getAttribute("m_id"),obj.getAttribute("m_nam"),obj.getAttribute("p_id"),obj.getAttribute("p_nam"),obj.getAttribute("i_len"),obj.getAttribute("i_wid"),obj.getAttribute("i_spe"),obj.getAttribute("f_con"),obj.getAttribute("m_req"),obj.getAttribute("i_uni"),thisAmount,"0",sNum,"0",obj.getAttribute("bb_item_id"),obj.getAttribute("bb_code"),obj.getAttribute("l_type"));
			
			parent.popRetVal=arr;
		}
		parent.ClosePop();
	}
	function getSquareNum(priceType,itemAmount,itemLength,itemWidth){
		itemSquareNum="0";
		if(priceType=="AREA"){
			itemSquareNum=accMul(accMul(itemLength,itemWidth),itemAmount);
			itemSquareNum=parseScale(itemSquareNum,2);
		}else if(priceType=="LENGTH"){
			itemSquareNum=accMul(itemLength,itemAmount);
			itemSquareNum=parseScale(itemSquareNum,2);
		}
		return itemSquareNum;
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		window.location="/cooper/BbItemListForCooperSelect.ihtm?"+str+"&current_page="+pageIndex;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr;
		if(ob_arr.length>=it.getAttribute("index")){
			var obj=ob_arr[it.getAttribute("index")-1];
			
			var thisAmount=abateMul(obj.getAttribute("i_amo"),obj.getAttribute("c_amo"));
			var sNum=getSquareNum("${priceType}",thisAmount,obj.getAttribute("i_len"),obj.getAttribute("i_wid"));
			arr=new Array(obj.getAttribute("m_id"),obj.getAttribute("m_nam"),obj.getAttribute("p_id"),obj.getAttribute("p_nam"),obj.getAttribute("i_len"),obj.getAttribute("i_wid"),obj.getAttribute("i_spe"),obj.getAttribute("f_con"),obj.getAttribute("m_req"),obj.getAttribute("i_uni"),thisAmount,"0",sNum,"0",obj.getAttribute("bb_item_id"),obj.getAttribute("bb_code"),obj.getAttribute("l_type"));
		
			parent.popRetVal=arr;
		}
		parent.ClosePop();
	}
	
	function doCancel(){
		parent.ClosePop();
	}
	function doInit(){
		//Window_Onload();
		document.getElementById("bill_code").focus();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function createPageParaStr(){
		var str="product_name="+encodeURIComponent(document.getElementById("product_name").value);
		str=str+"&content="+encodeURIComponent(document.getElementById("content").value);
		str=str+"&make_req="+encodeURIComponent(document.getElementById("make_req").value);
		str=str+"&mt_name="+encodeURIComponent(document.getElementById("mt_name").value);
		str=str+"&mt_id="+document.getElementById("mt_id").value;
		str=str+"&est_name="+encodeURIComponent(document.getElementById("est_name").value);
		str=str+"&bill_code="+encodeURIComponent(document.getElementById("bill_code").value);
		
		return str;
	}
	
	function createProgramParaStr(){
		var str="product_name="+encodeURIComponent(document.getElementById("hid_product_name").value);
		str=str+"&content="+encodeURIComponent(document.getElementById("hid_content").value);
		str=str+"&make_req="+encodeURIComponent(document.getElementById("hid_make_req").value);
		str=str+"&mt_name="+encodeURIComponent(document.getElementById("hid_mt_name").value);
		str=str+"&mt_id=${mtId}";
		str=str+"&est_name="+encodeURIComponent(document.getElementById("hid_est_name").value);
		str=str+"&bill_code="+encodeURIComponent(document.getElementById("hid_bill_code").value);
		
		return str;
	}
	function doSearch(){
		var str="price_type=${priceType}&ts_id=${tsId}&just_cooper=${justCooper}";
		if(IsAdvSearch){//高级
			str=str+"&search_type=1";
			if(document.getElementById("cb_pro").checked){
				var productName=document.getElementById("product_name").value.trim();
				if(productName==null || productName==""){
					ShowAlert('提示框','请输入材质',200,100);
					return;
				}
				str=str+"&cb_pro=1";
			}
			if(document.getElementById("cb_cont").checked){
				var content=document.getElementById("content").value.trim();
				if(content==null || content==""){
					ShowAlert('提示框','请输入内容',200,100);
					return;
				}
				str=str+"&cb_cont=1";
			}
			if(document.getElementById("cb_mr").checked){
				var makeReq=document.getElementById("make_req").value.trim();
				if(makeReq==null || makeReq==""){
					ShowAlert('提示框','请输入制作要求',200,100);
					return;
				}
				str=str+"&cb_mr=1";
			}
			if(document.getElementById("cb_mt").checked){
				var mtId=document.getElementById("mt_id").value;
				if(mtId==null || mtId=="" || mtId=="0"){
					ShowAlert('提示框','请选择项目类型',200,100);
					return;
				}
				str=str+"&cb_mt=1";
			}
			if(document.getElementById("cb_est").checked){
				var estName=document.getElementById("est_name").value.trim();
				if(estName==null || estName==""){
					ShowAlert('提示框','请输入订货单位',200,100);
					return;
				}
				str=str+"&cb_est=1";
			}
			if(document.getElementById("cb_bill_code").checked){
				var billCode=document.getElementById("bill_code").value.trim();
				if(billCode==null || billCode==""){
					ShowAlert('提示框','请输入业务单号',200,100);
					return;
				}
				str=str+"&cb_bill_code=1";
			}
		}else{//快速
			str=str+"&search_type=2";
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/cooper/BbItemListForCooperSelect.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="price_type=${priceType}&ts_id=${tsId}&just_cooper=${justCooper}&search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbPro=='1'}">str=str+"&cb_pro=1";</c:if>
			<c:if test="${cbCont=='1'}">str=str+"&cb_cont=1";</c:if>
			<c:if test="${cbMr=='1'}">str=str+"&cb_mr=1";</c:if>
			<c:if test="${cbMt=='1'}">str=str+"&cb_mt=1";</c:if>
			<c:if test="${cbEst=='1'}">str=str+"&cb_est=1";</c:if>
			<c:if test="${cbBillCode=='1'}">str=str+"&cb_bill_code=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function doAutoCheck(objId){
		if(document.getElementById(objId).style.visibility!="hidden"){
			document.getElementById(objId).checked=true;
		}
	}
	function selectMakeType(){
		var url="/base/MakeTypeListForSelect.ihtm";
		ShowIframe("选择项目类型",url,310,500,"selectMakeTypeCallBack()");
	}
	function selectMakeTypeCallBack(){
		if(popRetVal!=null){
			document.getElementById("mt_id").value=popRetVal[0];
			document.getElementById("mt_name").value=popRetVal[1];
			doAutoCheck("cb_mt");
		}
	}
</script>
</head>
<body oncontextmenu="return false">
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>业务单外协项目</h1>
	            <span class="Note">可以选择之前业务单未完成的外协项目，直接作为新外协单的项目</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_bill_code" id="cb_bill_code" <c:if test="${cbBillCode=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;">
			        		业务单号
	            		</th>
	            		<td class="c1" width="260px">
	            			<input type="text" class="TextBox" name="bill_code" id="bill_code" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_bill_code');" value="<c:out value="${billCode}" />" >
							<input type="hidden" id="hid_bill_code" value="<c:out value="${billCode}" />">
	            		</td>
	            	</table>
	            </span>
				<span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
		  			<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
								<input type="checkbox" name="cb_mt" id="cb_mt" <c:if test="${cbMt=='1'}">checked="true"</c:if> />
	            				项目类型
			        		</th>
			    			<td class="c1" width="260px">
			    				<input type="text" class="TextBox readonly" readonly="true" name="mt_name" id="mt_name" value="<c:out value="${mtName}" />" >
								<img class="imgIconButton" src="/images/make-a.gif" onClick="selectMakeType();" />
								<input type="hidden" id="hid_mt_name" value="<c:out value="${mtName}" />">
								<input type="hidden" name="mt_id" id="mt_id" value="${mtId}">
			    			</td>
			    			<th class="c2" width="80px">
			    				<input type="checkbox" name="cb_mr" id="cb_mr" <c:if test="${cbMr=='1'}">checked="true"</c:if>>
			        			制作要求
			        		</th>
			    			<td class="c3" width="280px">
			    				<input type="text" class="TextBox" name="make_req" id="make_req" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_mr');" value="<c:out value="${makeReq}" />" >
								<input type="hidden" id="hid_make_req" value="<c:out value="${makeReq}" />">
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
			        			<input type="checkbox" name="cb_cont" id="cb_cont" <c:if test="${cbCont=='1'}">checked="true"</c:if>>
			        			内容
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" name="content" id="content" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_cont');" value="<c:out value="${content}" />" >
								<input type="hidden" id="hid_content" value="<c:out value="${content}" />">
			    			</td>
							<th class="c2">
			        			<input type="checkbox" name="cb_est" id="cb_est" <c:if test="${cbEst=='1'}">checked="true"</c:if>>
			        			订货单位
			        		</th>
			    			<td class="c3">
			        			<input type="text" class="TextBox" name="est_name" id="est_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_est');" value="<c:out value="${estName}" />" >
								<input type="hidden" id="hid_est_name" value="<c:out value="${estName}" />">
			    			</td>
						</tr>
						<tr>
			    			<th class="c1">
			        			<input name="" type="checkbox" name="cb_pro" id="cb_pro" <c:if test="${cbPro=='1'}">checked="true"</c:if> />
			        			材质
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" id="product_name" name="product_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_pro');" value="<c:out value="${productName}" />">
								<input type="hidden" id="hid_product_name" value="<c:out value="${productName}" />">
			    			</td>
							<th class="c2">&nbsp;</th>
			    			<td class="c3">&nbsp;</td>
						</tr>
					</table>
					
					<div class="OptionOrderBy">
						<span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>
	        
		    <div class="table-list">
		        <table width="100%">
					<tr>
						<th width="8%" >订货日期</th>
						<th width="12%" >订货单位</th>
						<th width="10%">摘要</th>
						<th width="10%" >项目类型</th>
						<th width="12%" >内容</th>
						<th width="12%" >材质</th>
						<th width="10%" >规格</th>
						<th width="12%" >制作要求</th>
						<th width="5%" >单位</th>
						<th width="5%" >数量</th>
						<th width="4%" >操作</th>
					</tr>
					<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td>
							<input type="radio" onClick="javascript:ClickCheck(this);" name='query_checkbox' m_id="${item[1].businessBillItem.makeTypeId}" m_nam="<c:out value="${item[1].makeTypeName}" />" p_id="${item[1].businessBillItem.proId}" p_nam="<c:out value="${item[1].businessBillItem.proName}" />" i_len='<commonTag:parseBigDecimal source="${item[1].businessBillItem.length}" />' i_wid='<commonTag:parseBigDecimal source="${item[1].businessBillItem.width}" />' i_spe="<c:out value="${item[1].businessBillItem.specification}" />" f_con="<c:out value="${item[1].businessBillItem.finishedContent}" />" m_req="<c:out value="${item[1].businessBillItem.makeRequire}" />" i_uni="<c:out value="${item[1].businessBillItem.unit}" />" i_amo='<commonTag:parseBigDecimal source="${item[1].businessBillItem.amount}" />' u_pri='<commonTag:parseBigDecimal source="${item[1].businessBillItem.unitPrice}" />' s_num='<commonTag:parseBigDecimal source="${item[1].businessBillItem.squareNum}" />' i_cos='<commonTag:parseBigDecimal source="${item[1].businessBillItem.cost}" />' bb_item_id='${item[1].businessBillItem.id}' bb_code='${item[0].billCode}' c_amo='${item[1].businessBillItem.cooperedAmount}' l_type='${item[1].businessBillItem.lengType}' style="display:none"/>
							<fmt:formatDate value="${item[0].orderDate}" pattern="yyyy-MM-dd"/>
						</td>
						<td>${item[2]}</td>
						<td>${item[0].content}</td>
						<td>${item[1].makeTypeName}</td>
						<td>${item[1].businessBillItem.finishedContent}</td>
						<td>${item[1].businessBillItem.proName}</td>
						<td>${item[1].businessBillItem.specification}</td>
						<td>${item[1].businessBillItem.makeRequire}</td>
						<td>
							<c:if test="${priceType=='AREA'}">平方米</c:if>
							<c:if test="${priceType=='LENGTH'}">
								<c:if test="${item[1].businessBillItem.lengType=='M'}">米</c:if><c:if test="${item[1].businessBillItem.lengType=='CM'}">公分</c:if>
							</c:if>
							<c:if test="${priceType=='AMOUNT'}">${item[1].businessBillItem.unit}</c:if>
						</td>
						<td>
							<c:if test="${priceType=='AREA' || priceType=='LENGTH'}">${item[1].businessBillItem.squareNum}</c:if>
							<c:if test="${priceType=='AMOUNT'}">${item[1].businessBillItem.amount}</c:if>
						</td>
						<td>
							<a href="javascript:doSelect('${i.index+1}');">选择</a>
						</td>
					</tr>
					</c:forEach>
				</table>
			</div>

			<!-- 底栏 分页、操作等 -->
	        <div class="BottomToolBar ClearFix">
			    <%@include file="../inc/Pages.jsp"%>
	        </div>
			
		</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<970 ) w1 = 960;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_bill_code').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_bill_code').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
